﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CDB.LinqModel.Data;
using CDB.LinqData;
using System.Web.UI.HtmlControls;

public partial class Blog : System.Web.UI.Page
{
    #region Variable Declaration

    private IDataRepository _dataObject = new DataRepository();
    private CDB.LinqModel.Blog blog;
    private List<CDB.LinqModel.Blog> blogs = new List<CDB.LinqModel.Blog>();

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindBlogs();
        }
    }
    private void BindBlogs()
    {
        blog = new CDB.LinqModel.Blog(_dataObject);
        blogs = blog.GetAllBlogs();

        if (blogs.Count > 0)
        {
            grdBlog.DataSource = blogs;
            grdBlog.DataBind();
        }
    }
    protected void grdBlog_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HtmlGenericControl blogName = (HtmlGenericControl)e.Row.FindControl("blogName");
            HtmlGenericControl paraContent = (HtmlGenericControl)e.Row.FindControl("paraContent");
            Label lblName = (Label)e.Row.FindControl("lblName");
            Label lblDate = (Label)e.Row.FindControl("lblDate");
            Label lblContent = (Label)e.Row.FindControl("lblContent");

            blogName.InnerHtml = "<h2>" + lblName.Text + "</h2> Posted on " + Convert.ToDateTime(lblDate.Text).ToString("MMMM dd, yyyy");
            paraContent.InnerHtml = Server.HtmlDecode(lblContent.Text);
        }
    }
}